home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tclX6.4c / dist / tests / lgets.test < prev    next >
Encoding:
Text File  |  1992-11-07  |  4.2 KB  |  153 lines

  1. #
  2. # lgets.test
  3. #
  4. # Tests for the lgets command.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: lgets.test,v 2.0 1992/10/16 04:49:57 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21. Test lgets-1.1 {lgets command} {
  22.     lgets
  23. } 1 {wrong # args: lgets fileId [varName]}
  24.  
  25. Test lgets-1.2 {lgets command} {
  26.     lgets a b c
  27. } 1 {wrong # args: lgets fileId [varName]}
  28.  
  29. Test lgets-1.3 {lgets command} {
  30.     lgets a
  31. } 1 {bad file identifier "a"}
  32.  
  33. set f [open test2.tmp w]
  34. Test lgets-1.4 {lgets command} {
  35.     lgets $f
  36. } 1 "\"$f\" wasn't opened for reading"
  37. catch {close $f}
  38.  
  39. set f [open test2.tmp w]
  40. puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" nonewline
  41. puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" nonewline
  42. puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" nonewline
  43. puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" nonewline
  44. puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  45. close $f
  46.  
  47. Test lgets-1.5 {lgets command with long line} {
  48.     set f [open test2.tmp]
  49.     set x [lgets $f]
  50.     close $f
  51.     set x
  52. } 0 {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
  53.  
  54. Test lgets-1.6 {lgets command with long line} {
  55.     set f [open test2.tmp]
  56.     set x [lgets $f y]
  57.     close $f
  58.     list $x $y
  59. } 0 {260 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
  60.  
  61. Test lgets-1.7 {lgets command and end of file} {
  62.     set f [open test2.tmp w]
  63.     puts $f "Test1\nTest2" nonewline
  64.     close $f
  65.     set f [open test2.tmp]
  66.     set x {}
  67.     set y {}
  68.     lappend x [lgets $f y] $y
  69.     set y {}
  70.     lappend x [lgets $f y] $y
  71.     set y {}
  72.     lappend x [lgets $f y] $y
  73.     close $f
  74.     set x
  75. } 0 {5 Test1 5 Test2 -1 {}}
  76.  
  77. Test lgets-2.1 {lgets command} {
  78.     catch {unset data}
  79.     set data(0) [list aaa b cccc]
  80.     set data(1) [list aaaa \" ccc]
  81.     set data(2) [list aaaaa \" cc]
  82.     set data(3) [list aaaaa \"\" \} \{ \n c]
  83.     set data(4) [list bcad \n defg \n nypq]
  84.     set data(5) [list {BCAD  {AAA
  85. BBB
  86. CCC}
  87. defg
  88. nypq}]
  89.     set data(6) [list [replicate ABD 200]  "\n" [replicate XYZ 100]]
  90.     set data(7) [list [replicate ABD 255]  "\n" [replicate XYZ 100]]
  91.     set data(8) [list [replicate ABD 256]  "\n" [replicate XYZ 100]]
  92.     set data(9) [list [replicate "AAA\nBBB" 100]]
  93.  
  94.     set fh [open test1.tmp w]
  95.     loop idx 0 10 {
  96.         puts $fh $data($idx)
  97.     }
  98.     close $fh
  99.     set fh [open test1.tmp]
  100.     concat {}
  101. } 0 {}
  102.  
  103. Test lgets-2.2 {lgets command} {
  104.     lgets $fh
  105. } 0 $data(0)
  106.  
  107. Test lgets-2.3 {lgets command} {
  108.     lgets $fh retvar
  109.     set retvar
  110. } 0 $data(1)
  111.  
  112. Test lgets-2.4 {lgets command} {
  113.     lgets $fh
  114. } 0 $data(2)
  115.  
  116. Test lgets-2.5 {lgets command} {
  117.     lgets $fh retvar
  118.     set retvar
  119. } 0 $data(3)
  120.  
  121. Test lgets-2.6 {lgets command} {
  122.     lgets $fh
  123. } 0 $data(4)
  124.  
  125. Test lgets-2.7 {lgets command} {
  126.     lgets $fh retvar
  127.     set retvar
  128. } 0 $data(5)
  129.  
  130. Test lgets-2.8 {lgets command} {
  131.     lgets $fh retvar
  132.     set retvar
  133. } 0 $data(6)
  134.  
  135. Test lgets-2.9 {lgets command} {
  136.     lgets $fh retvar
  137.     set retvar
  138. } 0 $data(7)
  139.  
  140. Test lgets-2.10 {lgets command} {
  141.     lgets $fh retvar
  142.     set retvar
  143. } 0 $data(8)
  144.  
  145. Test lgets-2.11 {lgets command} {
  146.     lgets $fh retvar
  147.     set retvar
  148. } 0 $data(9)
  149.  
  150. catch {close $fh}
  151. unlink -nocomplain {test1.tmp test2.tmp}
  152.  
  153.